<template>
	<view class="study-detail">
		<view v-if="!showLoading">
			<u-swiper :list="info.commentInfo.visualsList" height="600rpx" @change="change" @click="click"></u-swiper>
			<view class="info">
				<view class="title">
					{{info.commentInfo.content}}
				</view>
			</view>
			<view class="comment-rate">
				<u-rate :value="info.commentInfo.grade" readonly size="24"></u-rate>
				<view class="date">
					纪实日期：{{info.commentInfo.createDate}}
				</view>
			</view>
			<view class="comment-user">
				<u--image :src="info.commentInfo.creatorAvatar? info.commentInfo.creatorAvatar : '/static/images/avatar-icon.png'" width="24" height="24" shape="circle" ></u--image>
				<text>{{info.commentInfo.creatorName}}</text>
			</view>
			<view class="event" v-if="info.eventCard.id">
				<view class="event-title">
					周边相关研学
				</view>
				<view class="event-list">
					<view class="event-list-item" @click="toEventDetail(info.eventCard.id)">
						<view class="event-list-item-title">
							{{info.eventCard.name}}
						</view>
						<view class="event-list-item-subtitle">
							研学时间：{{info.eventCard.time}}
						</view>
						<view class="event-list-item-subtitle">
							研学地址：{{info.eventCard.address}}
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view v-else>
			<u-skeleton rows="0" titleWidth="100%" titleHeight="200"></u-skeleton>
			<view class="info">
				<u-skeleton rows="2" titleWidth="100%" rowsWidth="100%"></u-skeleton>
			</view>
			<view class="comment-rate">
				<u-row gutter="30">
					<u-col span="4">
						<u-rate :value="0" readonly></u-rate>
					</u-col>
					<u-col span="18">
						<u-skeleton rows="0" titleWidth="100%"></u-skeleton>
					</u-col>
				</u-row>
			</view>
			<view class="comment-user">
				<u-row :gutter="30">
					<u-col span="2">
						<u-skeleton avatar avatarSize="48"></u-skeleton>
					</u-col>
					<u-col span="3">
						<u-skeleton rows="0" titleWidth="100%" title></u-skeleton>
					</u-col>
				</u-row>
			</view>
			<view class="event">
				<view class="event-title">
					周边相关研学
				</view>
				<view class="event-list-item">
					<u-skeleton rows="2" titleWidth="50%" rowsWidth="70%"></u-skeleton>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				showLoading: true,
				info: {},
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.getInfo(this.id);
		},
		onPullDownRefresh() {
			this.getInfo(this.id);
			uni.stopPullDownRefresh();
		},
		methods: {
			async getInfo(id) {
				const res = await this.$api('/study/mobile/comment/info', 'get', {
					id
				});
				this.showLoading = false;
				this.info = res.data;
			},

			toEventDetail(id) {
				uni.navigateTo({
					url: `/pages/study/event-detail?id=${id}`
				})
			},
			
			tobuy(buyUrl) {
				uni.navigateTo({
					url: `/pages/study/tobuy?buyUrl=${buyUrl}`
				})
				// this.showWebView = true;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.study-detail {
		padding-bottom: 150rpx;

		.info {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #fff;
			border-radius: 20rpx;

			.title {
				padding-bottom: 20rpx;
				border-bottom: 1rpx solid #ddd;
				font-size: 32rpx;
				color: #218BCC;
			}

			.info-item {
				padding-top: 20rpx;
				font-size: 28rpx;
				color: #666;
			}
		}

		.comment-rate {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 20rpx 20rpx 40rpx;
			
			.date {
				color: #666;
				font-size: 26rpx;
			}
		}
		
		.comment-user {
			padding: 0rpx 20rpx 20rpx 40rpx;
			display: flex;
			align-items: center;
			
			text {
				color: #444;
				padding-left: 10rpx;
			}
		}

		.event {
			margin: 40rpx 20rpx;

			&-title {
				padding-left: 20rpx;
				font-size: 32rpx;
				color: #74BB2A;
			}

			&-list {
				&-item {
					background-color: #fff;
					margin-top: 20rpx;
					padding: 20rpx;
					border-radius: 20rpx;

					&-title {
						margin-bottom: 20rpx;
						padding: 20rpx 0;
						border-bottom: 1rpx solid #ddd;
						color: #218BCC;
						font-size: 32rpx;
					}

					&-subtitle {
						font-size: 28rpx;
						color: #999;
					}
				}
			}
		}
	}
</style>